<?php require_once('../../../core/import.php');?>
<?php User::Permission('SLIDE_EDIT'); ?>
<?php
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
         #图片处理
        $Result=Upload::Probe($_FILES['File'],Config::UPLOAD_ATTACHMENT_SIZE_IMAGE,Config::UPLOAD_ATTACHMENT_EXT_IMAGE,Config::PATH_UPLOAD_ATTACHMENT_TEMP);
        
        #上传处理
        $Filename=NULL;
        if($Result['error']==UPLOAD_ERR_NO_FILE)    //如果上传了文件
        {
			echo '1|请上传图片';
        }
		else
		{
            switch($Result['error'])
            {
				//正确上传
                case UPLOAD_ERR_OK:
					//-更新数据
                    $Filename=Upload::Execute($_FILES['File'],Config::PATH_UPLOAD_ATTACHMENT_TEMP);									
					$ID=Functions::FormArgs('ID');
					DB::UpdateRowByID('slide',$ID,array
					(
						'PictureFilename'=>$Filename
					));					
					echo '0|'.Config::PATH_RELATIVE_ATTACHMENT_TEMP.'/'.$Filename;	
					//-保存文件
					$Tmp=DB::GetRowByID('slide',$ID);					
					$Data=DB::PGetRows('select * from slide where Class=? order by ID asc',array($Tmp['Class']));
					$XML='<?xml version="1.0" encoding="utf-8"?><bcaster autoPlayTime="3">';
					{
						foreach($Data as $Row)
						{
							$XML=$XML.'<item item_url="'.Config::PATH_RELATIVE_ATTACHMENT_TEMP.'/'.$Row['PictureFilename'].'" link="'.$Row['URL'].'" itemtitle=""></item>';
						}
					}
					$XML=$XML.'</bcaster>';	
					$fp=fopen(ROOT.'/data/slide/'.strtolower($Tmp['Class']).'.xml','w');
					{
						fwrite($fp,$XML);
						fclose($fp);
					}
					$fp=NULL;	
                break;
				//扩展名不正确
                case Upload::UPLOAD_ERR_CUSTOM_EXT:
                    echo '2|'.join(',',Upload::$UPLOAD_EXT_IMAGE);
                break;
				//图片大小不正确
                case Upload::UPLOAD_ERR_CUSTOM_SIZE:
                    echo '3|'.Functions::SizeFormat(Config::UPLOAD_ATTACHMENT_SIZE_IMAGE);
                break;
				//意外错误
                default :
                    echo '4|错误代码：'.$Result['error'].'，错误描述：'.$Result['message'].'。"}';
            }			
		}	
	}
?>